/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FarmacieDALManagers;

import FarmacieDAL.Users;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
/**
 *
 * @author Administrator
 */
public class UsersManager {
    
    private EntityManager em;
    
    public UsersManager(EntityManagerFactory emf) {
        em = emf.createEntityManager();
    }
    
     public void createUser(Users user) {
        em.getTransaction().begin();
        em.persist(user);
        em.getTransaction().commit();
    }

    public Users searchById(Integer id) {
        return em.find(Users.class, id);
    }

    public void updateUser(Users user) {
        em.getTransaction().begin();
        em.merge(user);
        em.getTransaction().commit();
    }

    public void removeUser(Users user) {
        em.getTransaction().begin();
        em.remove(user);
        em.getTransaction().commit();
    }

    public List getAll() {
        Query query = em.createQuery("select a from Users a");
        List list = query.getResultList();
        return list;
    }

    public void close() {
        em.close();
    }

}
